package com.bridgeintelligent.tag.webserver.workflow;

import com.github.pagehelper.Page;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public interface SubmitterService {

    @Data
    @Accessors(chain = true)
    class SubmitParam {
        String instanceId;
        String resourceId;
        String workflowId;
    }

    Instance submit(SubmitParam param);

    Instance fetchOne(String instanceId);

    @Data
    @Accessors(chain = true)
    class FetchAllParam {
        private List<String> workflowIds;
        private boolean containsDeleted;
        private int pageNum;
        private int pageSize;

        public FetchAllParam addWorkflowId(String workflowId) {
            if (workflowIds == null) {
                workflowIds = new ArrayList<>();
            }
            workflowIds.add(workflowId);
            return this;
        }
    }

    Page<Instance> fetchAll(FetchAllParam param);

    @Getter
    @Setter
    @Accessors(chain = true)
    class FetchByResourcesParam {
        private List<String> resourceIds;
        private boolean containsDeleted;
        private int currentStatus;

        public FetchByResourcesParam addResourceId(String resourceId) {
            if (resourceIds == null) {
                resourceIds = new ArrayList<>();
            }
            resourceIds.add(resourceId);
            return this;
        }
    }

    Map<String, Instance> fetchByResources(FetchByResourcesParam param);
}
